<?php
class articleAction extends security_normal {
	
	function action(){	
		$CategoryFN=$this->_getParamId(1);
		$ArticleFN=$this->_getParamId(2);
		$htmlfn=MICE_DIR.'article/'.$CategoryFN.'/'.$ArticleFN;
		if(MICE_HTML){
				if(file_exists($htmlfn)){
				include_once $htmlfn;
				exit;
			}
		}
		$ArticleId=preg_replace("/(\w+)_(\d+)".MICE_HTML_EXT."/i","\${2}",$ArticleFN);
		
		if($ArticleId<1)	$ArticleId=1;
		
		if($CategoryFN!='' and is_numeric($ArticleId)){
			global $conn;
			//查找分类
			$category=new model_Category();
			if(is_numeric($CategoryFN)){
				$category->setSubsection('WHERE type LIKE \'article%\' AND isvisible=0 AND (filename=\''.$CategoryFN.'\' OR category_id='.$CategoryFN.')');
			}else{
				$category->setSubsection('WHERE type LIKE \'article%\' AND isvisible=0 AND filename=\''.$CategoryFN.'\'');
			}
			$CategoryRS=$category->doSelectOne();
			$CategoryId=$CategoryRS->getCategoryId();

			if($CategoryRS){
				if($CategoryRS->getSubtpl()){								//模板
					$tpl=$CategoryRS->getSubtpl();
				}else{
					$filename = new getTPLFileName(__CLASS__);
					$tpl=$filename->TPLFileName;
				}
				//查找文章
				$article=new model_Article();
				$article->setSubsection('WHERE isvisible=0 AND category_id LIKE \'%,'.$CategoryId.',%\' AND article_id='.$ArticleId);
				$ArticleRS=$article->doSelectOne();
				if(!$ArticleRS){
					MessageBox('错误信息',MICE_URL,'对不起,您查看的文章不存在或已经被删除');
					exit;
				}
				if($ArticleRS->getUrl()){
					//跳转
					echo '<html><body><Script LANGUAGE="JavaScript">window.open("'.MiceRestoreQuote('micefun',$ArticleRS->getUrl()).'" ,"_parent");history.back(-1);</script></body></html>';
					exit;
				}
			}else{
				MessageBox('错误信息',MICE_URL,'对不起,您查看的文章不存在或已经被删除');
				exit;
			}
		}else{
			MessageBox('参数错误',MICE_URL);
			exit;
		}
		if($ArticleRS->getGroupId()<0){
			$gid=$CategoryRS->getGroupId();
		}else{
			$gid=$ArticleRS->getGroupId();
		}
		$miceSession = new session();
		if($gid>0)
		{			
			if($miceSession->get('mu__grouplevel')<$gid){
				MessageBox('只有会员才能查看,您尚未登录或注册',MICE_URL.'index.php');
				exit;
			}
		}

		//作者
		$user=new model_User();
		$user->setSubsection('where user_id='.$ArticleRS->getUserId());
		$userrs=$user->doSelectOne();
		$wname=$userrs->getLoginname();

		$smarty = new Smarty();
		$smarty->load_filter('pre','micePreCompileIndex');
		$smarty->assign('CategoryRS',$CategoryRS);
		$smarty->assign('ArticleRS',$ArticleRS);
		$smarty->assign('CategoryId',$CategoryId);
		$smarty->assign('ArticleId',$ArticleId);
		$smarty->assign('wname',$wname);
		
		if(MICE_HTML){
			//将内容写入至静态文件
			$content = $smarty->fetch($tpl);
			$fp = fopen($htmlfn, 'w'); 
			fwrite($fp, $content); 
			fclose($fp);
		}

		$smarty->display($tpl);
	}
}
?>